
**************************************************************************************
******INTERNET USE AND THE WELL-BEING OF THE ELDERS. A QUANTITATIVE STUDY IN AN AGED COUNTRY******
**************************************************************************************
*Authors: Ana Suárez Álvarez & María Rosalía Vicente

****************************
*CHOOSE THE RIGHT DIRECTORY
****************************
cd "Your directory"

**********************
**DATA PREPARATION*
**********************


*It is important to weight data using "anweight" -see "ESS_weighting_data_1_1.pdf" for more info. 
destring anweight, replace
*Keep only Spanish data
keep if cntry=="ES"
count
*Generate variable year -year of the survey-
gen year=.
replace year=2016 if essround==8
replace year=2018 if essround==9
gen r9=(essround==9)
sort year 
by year: count
*Internet related variables: netusoft & netustm -only asked if netusoft==4 OR 5-

*Subjective Wb Variables: happy, stlife sclmeet inprdsc sclact


global descrip "happy stflife sclmeet sclact netusoft netustm"

foreach var of global descrip {
sum `var' [aweight = anweight] ,de

}
pwcorr $descrip [aweight = anweight]
tabstat netustm, by(netusoft) stats (n mean)
gen daily_internet=(netusoft>3) //internet use daily or mostly daily
gen freq_internet= netusoft //Three categories nada, poco, mucho
replace freq_internet = 2 if netusoft==3
replace freq_internet = 3 if netusoft==4
replace freq_internet = 3 if netusoft==5

tab daily_internet essround, col
gen internet_time=netustm


*Discrimination for age (dscrage): usar para descriptivos? Share of dscrage by age group
gen young=(agea<25)
gen adulty=inrange(agea, 25,45)
gen adulto=inrange(agea,46,65)
gen old=(agea>65)
gen old60=(agea>60)
recode agea (1/24 =1) (25/39 =2) (40/50=3) (51/60=4) (61/100=5), gen(agegroup2)
label define groupage2 1 "<25" 2 "25-39" 3 "40-50" 4 "51-60" 5">60"
label values agegroup2 groupage2



*Sociodemographics
	**General SWB:
sum happy [aweight = anweight] //How happy are you, from 00 extremely unhappy to 10 extremely happy -77 refulal, 88 don't know.
sum stflife [aweight = anweight] //How satisfied with life as a whole, from 0 extremely dissatisfied to 10 extremely satisfied.

	**Social life:
sum sclmeet [aweight = anweight] //How often socially meet with friends, relatives or colleagues -from 1 never to 7 every day
sum inprdsc [aweight = anweight] // How many people with whom you can discuss intimate and personal matters -from 00 none to 06 10 or more-
sum sclact  [aweight = anweight] // Take part in social activities compared to others of same age -fromm 1 much less to 5 much more-
 
tab health [aweight = anweight] //subjective health: 1 (very good) 5 (very bad)
tab hlthhmp [aweight = anweight] //disability -Hampered in daily activities by illness/disability/infirmity/mental problem-
gen hampered=(hlthhm<3)
sum dscrage dscrgnd dscrdsb [aweight = anweight] //discrimination for: age / gender / disability 
tab bthcld [aweight = anweight] //children: different questions R9: Ever given birth to/ fathered a child & R8: more similar var is called "chldhhe": Have you ever had any children of your own, step-children, adopted children,foster children or a partner's children living in your household? which is also available in R9./ bthcld var is n.a in round 8 since it belongs to the module/rotating section "timing- timing of life" which is carried out only in R9 & R3 !! It would be better to use chldhhe ¿?

*Crosstabs internet and social life
tab netusoft sclmeet [aweight = anweight], col 
tab daily_internet sclmeet [aweight = anweight], col  
tab sclmeet daily_internet  [aweight = anweight], row  
tab sclmeet daily_internet, row chi  V

tab netusoft inprdsc [aweight = anweight], col
tab inprdsc daily_internet, row
tab inprdsc daily_internet, col V chi taub


tab netusoft sclact [aweight = anweight], col
tab daily_internet sclact [aweight = anweight], col

gen livingpartner=(rshipa2==1 | rshipa3==1| rshipa4==1| rshipa5==1| rshipa6==1| rshipa7==1| rshipa8==1| rshipa9==1| rshipa10==1| rshipa11==1| rshipa12==1| rshipa13==1| rshipa14==1| rshipa15==1)	
tab marsts [aweight = anweight]
gen hhsize=hhmmb 
gen female=(gndr==2)
label define fem 0 "Male" 1 "Female"
label values female fem
sum agea [aweight = anweight] // age of respondent 
tab eisced [aweight = anweight]  //highest level of education isced (there is also edulvlb which is an harmonised variable gen from ctry specific vars, it has more categories)
gen employed=pdwrk //Dummy 1 working 0 not working
sum emprel [aweight = anweight]  //Status in employment 1 employee 2 self-employed 3 family business
gen hhdecile=hinctnta //household income decile: subjetive 
sum hhdecile
sum hincfel [aweight = anweight]  // feelings about hh's income
tab domicil [aweight = anweight] //subjective habitat: respondent's description


*Include internet speed data:
merge m:1 region using speed.dta
drop _merge

*Recode deciles to take acount dk/da
gen decile_r=(hhdecile>5)
replace decile_r=2 if hhdecile==.a |hhdecile==.b| hhdecile==.c
tab decile_r
label define decil 0 "at most 5th decile" 1 "more than 5th decile" 2 "dk/da"
label values decile_r decil
tab decile_r hincfel, V chi
pwcorr hhdecile hincfel, star (0.01)

*Generate dummy variables
gen rural=(domicil>3) //living country village or home in countryside
gen badhealth=(health>2) //fair bad and very bad health
gen badhincfel=(hincfel>2) // difficult/very difficult on present income
tab rural
gen more_5decile=(decile_r==1) // Richest 50%
tab eisced, gen(estu)
gen tertiary=(eisced==6|eisced==7)
global x "female agea i.eisced employed rural more_5decile"
logit daily_internet $x r9 max
estat gof, group(10)
estat class

*Internet time:
**ajustando bien daily_internet e internet_time 
tab daily_internet
sum internet_time
replace daily_internet=0 if internet_time==.a | internet_time==.b |internet_time==.c |internet_time==.d | internet_time==.e



**********************************************************
*Difference mean test (Table I)
**********************************************************
ttest happy, by(daily_internet)
ttest stflife, by(daily_internet)
ttest sclmeet, by(daily_internet)
ttest inprdsc, by(daily_internet)
ttest sclact, by(daily_internet)

**********************************************************
*Difference mean test (Table II)
*********************************************
ttest happy, by(old60)
ttest stflife, by(old60)
ttest sclmeet, by(old60)
ttest inprdsc, by(old60)
ttest sclact, by(old60)

*********
**Figure 1
**********
ciplot daily_internet [aweight=anweight], by(agegroup2) scheme(s1mono) xtitle(Age group) ytitle(% Using internet daily)


****************
***Mean test (Table III)
******************
gen oldinternet = .
replace oldinternet = 1 if daily_internet==1 & old60==1
replace oldinternet = 0 if daily_internet==0 & old60==1
sum oldinternet

ttest happy, by(oldinternet)
ttest stflife, by(oldinternet)
ttest sclmeet, by(oldinternet)
ttest inprdsc, by(oldinternet)
ttest sclact, by(oldinternet)
************************************************

*********************
****MODELS TABLE 4****
***********************

cmp setup
global x1 "agea eisced employed i.decile_r rural r9 max"
global x2_wb "badhealth hampered hampered##daily_internet livingpartner female female##daily_internet agea old60##daily_internet  employed i.domicil i.hincfel r9" 

cmp (daily_internet=$x1) (stflife=$x2_wb daily_internet) [aweight = anweight], ind($cmp_probit $cmp_cont) nonrtolerance
	estimates store o1
cmp (daily_internet=$x1) (happy=$x2_wb daily_internet) [aweight = anweight], ind($cmp_probit $cmp_cont) nonrtolerance
	estimates store o2
cmp (daily_internet=$x1) (sclmeet=$x2_wb daily_internet) [aweight = anweight], ind($cmp_probit $cmp_cont) nonrtolerance
	estimates store o3
cmp (daily_internet=$x1) (inprdsc=$x2_wb daily_internet) [aweight = anweight], ind($cmp_probit $cmp_cont) nonrtolerance
	estimates store o4
cmp (daily_internet=$x1)  (sclact=$x2_wb daily_internet) [aweight = anweight], ind($cmp_probit $cmp_cont) nonrtolerance
	estimates store o5		
	outreg2 [o*] using cmp_2eqnintoldd.xls, replace dec(4) alpha(0.01, 0.05, 0.1) label		
	
